using System;
using System.Resources;
using System.Reflection;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;
using System.Collections.Generic;
using System.Collections;

namespace DVK.SP2007
{
    /// <summary>
    /// Contains the extension methods for ResourceManager class.
    /// </summary>
    public static class ResourceManagerExtensions
    {
       /// <summary>
        /// Gets the resource based on enum element.
        /// 
        /// Extension methods.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="resourceManager">The resource manager.</param>
        /// <param name="enumValue">The enum value.</param>
        /// <returns>localized string</returns>
        public static string GetResourceBasedOnEnumElement<T>(this ResourceManager resourceManager, T enumValue)
        {
            Type enumType = typeof(T);
            string name = Enum.GetName(enumType, enumValue);
            return resourceManager.GetString(enumType.Name + "_" + name);
        }

        /// <summary>
        /// Gets the resource based on enum element.
        /// The data inputed will be used in string.Format to fill in the data gaps in the localized string.
        /// Extension method.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="resourceManager">The resource manager.</param>
        /// <param name="enumValue">The enum value.</param>
        /// <param name="data">The data array.</param>
        /// <returns>localized string</returns>
        public static string GetResourceBasedOnEnumElement<T>(this ResourceManager resourceManager, T enumValue, params object[] data)
        {
            Type enumType = typeof(T);
            string name = Enum.GetName(enumType, enumValue);
            return string.Format(resourceManager.GetString(enumType.Name + "_" + name), data);
        }
    }
}